/**
 *
 */
package com.rf.richfitwheel.workflow.service;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import com.rf.richfitwheel.admin.sys.vo.UserVO;
import com.rf.richfitwheel.workflow.model.WfProcessTask;
import com.rf.richfitwheel.workflow.model.WfStationProcess;
import com.rf.richfitwheel.workflow.model.WfStationProcessOrder;
import org.activiti.bpmn.model.StartEvent;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.repository.Model;
import org.activiti.engine.repository.ProcessDefinition;
import org.apache.batik.transcoder.TranscoderException;
import org.springframework.web.multipart.MultipartFile;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.rf.richfitwheel.common.utils.PageUtils;
import com.rf.richfitwheel.workflow.entity.ProcessVO;

/**
 * 流程模型设计
 * @author hushouquan
 *
 */
public interface ModelService {

    void addOrUpdate(Map<String, Object> params, UserVO user) throws IOException;

    PageUtils list(Map<String, Object> params, UserVO user);

    void deleteModel(String id);

    void deployModel(String id, UserVO user) throws Exception;

    List<WfProcessTask> getWfProcessTaskByProDefKey(String proDefKey);

    Model getById(String id);

    Model findByOrgCodeAndProcessCode(String orgCode, String processCode);

    Model findByProcessKey(String processKey);

    void deployModelExtendAndSetAuthor(Model model, WfStationProcess wsp, UserVO userVO, List<WfStationProcessOrder> wfStationProcessOrders) throws Exception;


    List<Model> getListByOrgCodeAndName(String orgCode, String processName);


    /**
     * 初始化一个空的模型
     * @param user
     * @return
     */
    String newModel(UserVO user);

    Model newModel(String orgCode, String processName, String processKey, String processCode, UserVO user);


    /**
     * 根据id加载模型数据
     * @param modelId
     * @return
     * @throws Exception
     */
    ObjectNode getEditorJson(String modelId) throws Exception;

    /**
     * 删除一个空模型
     * @param modelId
     */
    void deleteNoneModel(String modelId);

    /**
     * 获取最新版的流程定义
     * @return
     */
    List<ProcessDefinition> getProcessOption();

    /**
     * 修改模型
     * @param modelId
     * @param name
     * @param description
     * @param json_xml
     * @param svg_xml
     * @throws Exception
     */
    void saveModel(String modelId, String name, String description, String json_xml, String svg_xml) throws Exception;

    /**
     * 发布模型
     * @param id
     * @param user
     * @throws Exception
     */
    void deploy(String id, UserVO user) throws Exception;

    /**
     * 加载流程文件内容
     * @param deploymentId
     * @param resType
     * @param processDefinition
     * @return
     */
    InputStream resourceRead(String deploymentId, String resType, ProcessDefinition processDefinition);

    /**
     * 流程导入
     * @param files
     * @param user
     * @throws Exception
     */
    void improtDeploy(List<MultipartFile> files, UserVO user) throws Exception;

    /**
     * 将流程转化为模型
     * @param procDefId
     * @return
     * @throws Exception
     */
    Model convertToModel(String procDefId) throws Exception;

    /**
     * 获取开始节点信息用于组织页面表单
     * @param defKey
     * @return
     */
    StartEvent getModelStartNodeInfo(String defKey);

    /**
     * 查询流程名称列表
     * @param tenantId
     *
     * @return
     */
    List<ProcessVO> getProcessNameList(String tenantId);

    String deploy1(String modelId, UserVO user);

    void updateModel(String modelId, String orgCode, String processName, String processKey, String processCode, UserVO userVO);

    Model copyModel(String templateModelId, String modelId, String orgCode, String processName, String processKey, String processCode, List<WfStationProcessOrder> wfStationProcessOrders) throws IOException;

    String copyModel(String orgCode, String processName, String processKey, String processCode, String modelId, UserVO userVO) throws IOException;

    void editMode(String modelId, Map<String, WfProcessTask> wfProcessTaskMap) throws IOException, TranscoderException;


    PageUtils queryHistoryDefinitionPage(Map<String, Object> params);

    List<WfProcessTask> getWfProcessTaskByProDefId(String id);
}
